package com.goods.business.controller;

import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author liangliang
 * @Date 2021/11/10 17:29 Administrator
 * @Description
 */
@RestController
@RequestMapping("/business/consumer/")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    /**
     * 查询物资去处
     * @param map
     * @return
     */
    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam Map map){
      PageVO<ConsumerVO>  consumerVOPageVO= consumerService.findConsumerList(map);
      return ResponseBean.success(consumerVOPageVO);
    }

    /**
     * 添加物资去处
     * @param consumerVO
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    /**
     * 根据ID查询物资出去用作数据回显
     * @param id
     * @return
     */
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
    ConsumerVO consumerVO=consumerService.edit(id);
    return ResponseBean.success(consumerVO);
    }

    /**
     * 修改数据
     * @param id
     * @param consumerVO
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody ConsumerVO consumerVO ){
        consumerService.update(id,consumerVO);
        return ResponseBean.success();
    }

    /**
     * 根据ID删除物资去处
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consumerService.delete(id);
        return ResponseBean.success();
    }

    /**
     * 物资去向
     * @return
     */
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<ConsumerVO> consumerVOList =consumerService.findAll();
        return ResponseBean.success(consumerVOList);
    }
}
